package com.ctshk.rpc.starvip.factory.user;

import com.ctshk.common.utils.EntityUtil;
import com.ctshk.rpc.starvip.dto.start_vip.user.*;
import com.ctshk.rpc.starvip.factory.StarVipReqProvider;
import com.ctshk.rpc.starvip.req.user.StarVipUserCreateOpUpdateReq;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * @BelongsProject: ctshk-cloud
 * @BelongsPackage: com.ctshk.rpc.starvip.factory.user
 * @Author: hef
 * @CreateTime: 2021-04-13 18:12
 * @Description: 描述
 */
public class UserCreateOrUpdateReqFactory extends StarVipReqProvider<StarVipUserCreateOpUpdateReq> {
    public UserCreateOrUpdateReqFactory(StarVipUserCreateOpUpdateReq req) {
        super(req);
    }

    @Override
    public StarVipCreateOrUpdateDTO produce() {
        Contact contact = EntityUtil.copy(req, Contact.class);
        List<LoyMember> loyMembers = Lists.newArrayList();
        /*req.getLoyMember().stream().forEach(item -> {
            LoyMember loyMember = EntityUtil.copy(item, LoyMember.class);
            loyMember.setListOfLOYMemberOrganization(
                    new ListOfLoyMemberOrganization(
                            EntityUtil.copyList(item.getLoyMemberOrganization(),LoyMemberOrganization.class)
                    )
            );
            loyMember.setListOfLOYMemberDominantTier(
                    new ListOfLoyMemberDominantTier(
                            EntityUtil.copyList(item.getLoyMemberDominantTier(), LoyMemberDominantTier.class)
                    )
            );
            loyMember.setListOfLoyMembershipCard(
                    new ListOfLoyMembershipCard(
                            EntityUtil.copyList(item.getLoyMembershipCard(), LoyMembershipCard.class)
                    )
            );
            loyMembers.add(loyMember);
        });
        contact.setListOfLoyMember(
                new ListOfLoyMember(loyMembers)
        );*/
        contact.setListOfContactOrganization(
                new ListOfContactOrganization(EntityUtil.copyList(req.getContactOrganization(), ContactOrganization.class))
        );
        contact.setListOfAlternatePhone(
                new ListOfAlternatePhone(EntityUtil.copyList(req.getAlternatePhone(), AlternatePhone.class))
        );
        contact.setListOfLoyCommunicationFax(
                new ListOfLoyCommunicationFax(EntityUtil.copyList(req.getLoyCommunicationFax(), LoyCommunicationFax.class))
        );
        contact.setListOfLoyCommunicationSms(
                new ListOfLoyCommunicationSms(EntityUtil.copyList(req.getLoyCommunicationSms(), LoyCommunicationSms.class))
        );
        contact.setListOfPersonalAddress(
                new ListOfPersonalAddress(EntityUtil.copyList(req.getPersonalAddress(), PersonalAddress.class))
        );
        contact.setListOfCtsMobilePhone(
                new ListOfCtsMobilePhone(EntityUtil.copyList(req.getCtsMobilePhone(), CtsMobilePhone.class)
                ));
        contact.setListOfContactAccount(
                new ListOfContactAccount(EntityUtil.copyList(req.getContactAccount(), ContactAccount.class))
        );
        contact.setListOfContactAccountAffiliation(
                new ListOfContactAccountAffiliation(EntityUtil.copyList(req.getContactAccountAffiliation(), ContactAccountAffiliation.class))
        );
        contact.setListOfContactNote(
                new ListOfContactNote(EntityUtil.copyList(req.getContactNote(), ContactNote.class))
        );
        contact.setListOfPartyRelationshipTo(
                new ListOfPartyRelationshipTo(EntityUtil.copyList(req.getPartyRelationshipTo(), PartyRelationshipTo.class))
        );
        StarVipCreateOrUpdateDTO starVipCreateOrUpdateDTO = new StarVipCreateOrUpdateDTO();
        starVipCreateOrUpdateDTO.setMessageId("1-KNFX");
        starVipCreateOrUpdateDTO.setIntObjectName("CIFContactUpsert");
        starVipCreateOrUpdateDTO.setInterfaceId("CTS_IF_03");
        //ID存在则是更新
        starVipCreateOrUpdateDTO.setOperation(StringUtils.isNotBlank(contact.getId())?"Update":"Insert");
        starVipCreateOrUpdateDTO.setMessageType("Integration Object");
        starVipCreateOrUpdateDTO.setIntObjectFormat("Siebel Hierarchical");
        starVipCreateOrUpdateDTO.setUpsertContact(new UpsertContact(
                contact
        ));
        return starVipCreateOrUpdateDTO;
    }
}
